package org.kwisatz.proxybot.filters;

import java.io.PrintWriter;

import org.kwisatz.proxybot.FilterAdapter;
import org.kwisatz.proxybot.Message;
import org.kwisatz.proxybot.Toolkit;

public class Bookmark extends FilterAdapter
{	
	private final static String COMMAND="!.";
	
	public String handleClientLine(String line, Message message)
	{
		if("PRIVMSG".equals(message.getCommand()) &&
			message.getEndOfMsg().startsWith(COMMAND))
		{
			String channel = message.getCmdParam();
			String eom = message.getEndOfMsg();			
			String nick="";
			int i=eom.indexOf(' ');
			String bookmark;

			if(i>=0)
			{
				nick = eom.substring(i+1)+"> ";
				bookmark = eom.substring(COMMAND.length(), i);
			}
			else
				bookmark = eom.substring(COMMAND.length());
			bookmark=bookmark.trim();
			
			PrintWriter pw = Toolkit.channelWriter(context, channel);
			String msg = nick+System.getProperty("proxybot.bk."+bookmark);
			if(msg != null)
				pw.println(msg);
		}
		return line;
	}	
}
